package net.kentop.flex;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

public class EchoService {

	public String echo(String text) {
		return "Server says: I received '" + text + "' from you";
	}

	public  byte[] loadImage() {

		String path = EchoService.class.getClassLoader().getResource("")
				.getPath()
				+ "wstx.jpg";

		File imageFile = new File(path);
		
		try {
			BufferedInputStream bufferedInputStream=new BufferedInputStream(new FileInputStream(imageFile));
			
		    long len = imageFile.length();
		    byte[] bytes = new byte[(int)len];
		    
		    bufferedInputStream.read(bytes);
		    
		    return bytes;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public  byte[] loadImage(String fileName) {

		String path = EchoService.class.getClassLoader().getResource("")
				.getPath()
				+ fileName;

		File imageFile = new File(path);
		
		try {
			BufferedInputStream bufferedInputStream=new BufferedInputStream(new FileInputStream(imageFile));
			
		    long len = imageFile.length();
		    byte[] bytes = new byte[(int)len];
		    
		    bufferedInputStream.read(bytes);
		    
		    return bytes;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public List<ListEntity> fileList(int fileType){
		
		if(fileType ==1 ||fileType ==2){
			
			if(fileType ==1){
				List<ListEntity> entitys = new ArrayList<ListEntity>();
				
				ListEntity entity1 = new ListEntity();
				entity1.setLabel("33_avatar_middle.jpg");
				entity1.setData(1);
				
				ListEntity entity2 = new ListEntity();
				entity2.setLabel("wstx2.jpg");
				entity2.setData(2);
				
				entitys.add(entity1);
				entitys.add(entity2);
				
				return entitys;
			}else{
				List<ListEntity> entitys2 = new ArrayList<ListEntity>();
				
				ListEntity entity1 = new ListEntity();
				entity1.setLabel("wstx.jpg");
				entity1.setData(1);
				
				ListEntity entity2 = new ListEntity();
				entity2.setLabel("middle_banner.jpg");
				entity2.setData(2);
				
				entitys2.add(entity1);
				entitys2.add(entity2);
				
				return entitys2;
			}
		}
		return null;
	}

//	public static void main(String[] args) {
//		System.out.println(loadImage());
//	}

}
